#include<iostream>
#include<fstream>
#include"contacts.pb.h"
using namespace std;
void PrintCon(contacts2::PeopleContacts& con)
{
    for(int i=0;i<con.cont_size();i++)
    {
        cout<<"-------------联系人"<<i+1<<"--------------------"<<endl;
        const contacts2::PeopleInfo& people = con.cont(i);
        cout<<"姓名："<<people.name()<<endl;
        cout<<"年龄："<<people.age()<<endl;
        for(int j=0;j<people.phione_size();j++)
        {
            const contacts2::PeopleInfo_Phone& phone = people.phione(j);
            cout<<"电话"<<j+1<<":"<<phone.number();
            cout<<"  ("<<phone.PhoneType_Name(phone.type())<<")"<<endl;
        }
        if(people.has_data()&&people.data().Is<contacts2::Address>())
        {
            contacts2::Address addr;
            people.data().UnpackTo(&addr);
            if(!addr.home_address().empty())
            {
                cout<<"家庭地址:"<<addr.home_address()<<endl;
            }
            if(!addr.unit_address().empty())
            {
                cout<<"单位地址:"<<addr.unit_address()<<endl;
            }
        }
        switch (people.other_contact_case())
        {
        case contacts2::PeopleInfo::OtherContactCase::kQq:
            cout<<"qq号码："<<people.qq()<<endl;
            break;
        case contacts2::PeopleInfo::OtherContactCase::kWechat:
            cout<<"wechat号码："<<people.wechat()<<endl;
            break;
        
        default:
            break;
        }
        if(!people.remake().empty())
        {
            cout<<"备注信息："<<endl;
        }
        for(auto it = people.remake().cbegin();it!=people.remake().cend();it++)
        {
            cout<<"   "<<it->first<<": "<<it->second<<endl;
        }
    }
}
int main()
{

    contacts2::PeopleContacts contacts;
    fstream input("test.bin",ios::in|ios::binary);
    if(!contacts.ParseFromIstream(&input))
    {
        cerr<<"parse error"<<endl;
        input.close();
        return 1;
    }
    PrintCon(contacts);
    return 0;
}